package com.bms.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bms.bean.ExamProjectType;
import com.bms.bean.User;
import com.bms.comm.Pagination;
import com.bms.comm.UserThread;
import com.bms.dao.ExamProjectTypeDao;

@Service
public class ExamProjectTypeService {
	
	@Resource
	private ExamProjectTypeDao examProjectTypeDao;
	
	public List<ExamProjectType> queryExamProjectTypeList(){
		Long userId = UserThread.getUserThread().getUserId();
		List<ExamProjectType> list = examProjectTypeDao.queryExamProjectTypeList(userId.toString());
		return list;
	}
	
	public Pagination<ExamProjectType> queryExamProjectTypeForPage(int pageSize,int curPageNo,String project_type_name){
		Long userId = UserThread.getUserThread().getUserId();
		
		if(project_type_name!=null && !"".equals(project_type_name)){
			project_type_name = project_type_name+"%";
		}
		
		Pagination<ExamProjectType> pagination = new Pagination<ExamProjectType>();
		pagination.setCurPageNo(curPageNo);
		pagination.setPageSize(pageSize);
		
		List<ExamProjectType> page = examProjectTypeDao.queryExamProjectTypeForPage(userId==null?"":userId.toString(),project_type_name,pagination);
		
		pagination.setDataList(page);
		return pagination;
	}
	
	public void saveExamProjectType(String examProjectName,String examProjectDesc ){
		
		User user   = UserThread.getUserThread();
		Long userId = user.getUserId();
		
		String projectTypeId        = examProjectTypeDao.getExamProjectTypeSequence();
		ExamProjectType projectType = new ExamProjectType();
		projectType.setProject_type_id(projectTypeId);
		projectType.setProject_type_name(examProjectName);
		projectType.setProject_type_desc(examProjectDesc);
		projectType.setCreator_id(userId==null?"":userId.toString());
		examProjectTypeDao.saveExamProjectType(projectType);
	}
	
	public void deleteExamProjectTypeById(String projectTyoeId){
		examProjectTypeDao.deleteExamProjectTypeById(projectTyoeId);
	}
}
